
<template name='goods_card'>
	<view class="box-infos font12  " >
		<!-- 列表区 -->
		<view class="content-box " >
			<view class="boxsss100" >
				<view class="top-but menu-scroll-w" >
					<view class="top-but-box">
						<text selectable="true"  class="tipss">已被使用的卡密允许被删除，因为已缓存到订单记录中；\n当用户下单被过账之后将会发送卡密至用户的订单详情页面中；</text>
						<button
						@click="AddGoodsCard(0)"
						class="leftBut color5" 
						>
							增加卡密(循环使用)
						</button>
						
						<button
						@click="AddGoodsCard(1)"
						class="leftBut color6" 
						>
							增加卡密(单次使用)
						</button>
						
						<button @click="$common.noMultipleClicks('resDataFun',resDataFun,true)"
						class="leftBut color1" 
						>
							<img src="../../static/img/search.png" class="ico" ></img>
							刷新
						</button>
					</view>
				</view>
				<table v-if="list &&  list.length>0">
					<!-- 表头 -->
					<thead>
						<tr >
							<th  class="centers " style="min-width: 20px;">
								序号
							</th>
							<th  >
								卡密
							</th>
							<th  class="centers ">
								类型
							</th>
							<th  class="centers ">
								状态
							</th>
							<th  class="centers ">
								操作
							</th>
						</tr>
					</thead>
					<tbody>
						<!-- 内容 -->
						<tr  
						:key="index" 
						@click="TabcheckedIndex=index"
						v-for="(item,index) in list" 
						:class="TabcheckedIndex == index ? 'goods-list-select':''"
						>
							<td  class="centers ">
								{{index+1}}
							</td>
							<td   class="centers">
								<text :selectable="true">{{item.card}}</text>
							</td>
							<td class="centers" >
								{{item.mode==0 ? '循环':'单次'}}
							</td>
							<td   class="centers" :class="item.status==1 ?'money_color':''">
								{{item.status==0 ? '未使用':'已使用'}}
							</td>
							<td   class="alter" @click="DeleteGoodsCard(item.id,index)">
								删除
							</td>
						</tr>
					</tbody>
				</table>
				<!-- 暂无数据 -->
				<empty v-if="list &&  list.length==0"></empty>
				<!-- end -->
			</view>
		</view>
		<!-- end -->
	</view>
</template>

<script>
	import empty from "@/components/admin-components/empty.vue"
	export default{
		name:'goods_card',
		components: {
			empty,
		},
		data(){
			return{
				TabcheckedIndex:-1,//当前选中项
				list:[],

			}
		},
		 // 此处定义传入的数据
		props: {
			OnGoodsId: '',//商品ID
		},
		created() {
			this.resDataFun(true)
		},
		methods:{
			
			//获取列表
			resDataFun(){
				var that = this
				that.$common.get_request(
					{
						type:'GetGoodsCard',
						goods_id: that.OnGoodsId,
					},
					(res)=>{
						that.list = res.list
					}
				);
			},
			//删除
			DeleteGoodsCard(id,index){
				var that = this
				that.$common.get_request(
					{
						type:'DeleteGoodsCard',
						id: id,
					},
					(res)=>{
						that.list.splice(index,1)
						that.$common.toast(res.msg)
					}
				);
			},
			//添加
			AddGoodsCard(mode){
				var that = this
				uni.showModal({
					title:'输入卡密',
					mask:true,
					editable:true,
					placeholderText:'请输入卡密',
					success:(res)=>{
						if(res.confirm ){
							if(res.content.length==0){
								that.$common.showModal('提示',"未输入内容")
								return
							}
							var card = res.content.trim();
							var value = card.split("\n");  
							that.$common.get_request(
								{
									type:'AddGoodsCard',
									mode: mode,
									card:value,
									goods_id:that.OnGoodsId
								},
								(e)=>{
									that.$common.toast(e.msg)
									that.resDataFun()
								}
							);
						}
					}
				})
			},
		}
	}
</script>

<style>
</style>
